package com.tnxst.phexamination.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.SavedStateViewModelFactory;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.google.android.material.button.MaterialButtonToggleGroup;
import com.tnxst.phexamination.R;
import com.tnxst.phexamination.adapter.follow.DiabetesFollowAdapter;
import com.tnxst.phexamination.adapter.follow.HypertensionFollowAdapter;
import com.tnxst.phexamination.adapter.follow.TbFirstRecordAdapter;
import com.tnxst.phexamination.adapter.follow.TbFollowAdapter;
import com.tnxst.phexamination.adapter.follow.TbPatientRecordAdapter;
import com.tnxst.phexamination.adapter.follow.TcmHealthFollowAdapter;
import com.tnxst.phexamination.constant.HISConfig;
import com.tnxst.phexamination.databinding.ActivityDoorRecordBinding;
import com.tnxst.phexamination.databinding.ActivityGoDoorRecordBinding;
import com.tnxst.phexamination.dto.DiabetesFollowDTO;
import com.tnxst.phexamination.dto.HypertensionFollowDTO;
import com.tnxst.phexamination.dto.TCMHealthDTO;
import com.tnxst.phexamination.dto.TbFirstFollowDTO;
import com.tnxst.phexamination.dto.TbFollowDTO;
import com.tnxst.phexamination.dto.TbPatientDTO;
import com.tnxst.phexamination.dto.TbPatientRecordDTO;
import com.tnxst.phexamination.fragment.RecordTcmHealthElderlyFragment;
import com.tnxst.phexamination.public_health_docking_interface.DiabetesInterface;
import com.tnxst.phexamination.public_health_docking_interface.HypertensionInterface;
import com.tnxst.phexamination.public_health_docking_interface.TCMHealthElderlyInterface;
import com.tnxst.phexamination.public_health_docking_interface.TuberculosisInterface;
import com.tnxst.phexamination.utils.GsonUtils;
import com.tnxst.phexamination.utils.ReflectUtils;
import com.tnxst.phexamination.utils.StringUtils;
import com.tnxst.phexamination.utils.Utils;
import com.tnxst.phexamination.utils.WebServiceUtils;
import com.tnxst.phexamination.viewmodel.GlobalViewModel;

import org.apache.commons.collections.CollectionUtils;

import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.concurrent.CountDownLatch;

public class DoorRecordActivity extends BaseActivity{

    private GlobalViewModel viewModel;

    private ActivityDoorRecordBinding binding;

    private Context context;

    private FragmentManager fragmentManager;

    private String name;

    private List<TbPatientRecordDTO> tbPatientRecordDTOS;

    private TbPatientRecordAdapter tbPatientRecordAdapter;

    private List<TbFirstFollowDTO> tbFirstFollowDTOS;

    private TbFirstRecordAdapter tbFirstRecordAdapter;

    private List<TbFollowDTO> tbFollowDTOS;

    private TbFollowAdapter tbFollowAdapter;

    private List<DiabetesFollowDTO> diabetesFollowDTOS;

    private DiabetesFollowAdapter diabetesFollowAdapter;

    private List<HypertensionFollowDTO> hypertensionFollowDTOS;

    private HypertensionFollowAdapter hypertensionFollowAdapter;

    private List<TCMHealthDTO> tcmHealthDTOS;

    private TcmHealthFollowAdapter tcmHealthFollowAdapter;

    private Integer isFinish = 0;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        viewModel = new ViewModelProvider(this, new SavedStateViewModelFactory(getApplication(), this)).get(GlobalViewModel.class);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_door_record);
        binding.setDoorRecord(viewModel);
        binding.setLifecycleOwner(this);
        fragmentManager = getSupportFragmentManager();
        context = this;
        initData();
        initView();
    }

    private void initView() {
        if (StringUtils.isNull(name))
            return;
        binding.textView2.setText(name);

        binding.imageView4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        binding.editText2.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                String iName = editable.toString();
                if (StringUtils.isNotNull(iName)){
                    switch (name){
                        case "老年人中医管理记录":
                            tcmHealthDTOS = viewModel.getTCMHealthRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                            tcmHealthFollowAdapter.setTcmHealthDTOS(tcmHealthDTOS);
                            tcmHealthFollowAdapter.notifyDataSetChanged();
                            break;
                        case "高血压随访记录":
                            hypertensionFollowDTOS = viewModel.getHypertensionFollowRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                            hypertensionFollowAdapter.setHypertensionFollowDTOS(hypertensionFollowDTOS);
                            hypertensionFollowAdapter.notifyDataSetChanged();
                            break;
                        case "糖尿病随访记录":
                            diabetesFollowDTOS = viewModel.getDiabetesFollowRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                            diabetesFollowAdapter.setDiabetesFollowDTOS(diabetesFollowDTOS);
                            diabetesFollowAdapter.notifyDataSetChanged();
                            break;
                        case "肺结核患者档案":
                            tbPatientRecordDTOS = viewModel.getTbPatientRecordRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                            tbPatientRecordAdapter.setTbPatientRecordDTOS(tbPatientRecordDTOS);
                            tbPatientRecordAdapter.notifyDataSetChanged();
                            break;
                        case "肺结核患者第一次入户随访记录":
                            tbFirstFollowDTOS = viewModel.getTbFirstFollowRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                            tbFirstRecordAdapter.setTbFirstFollowDTOS(tbFirstFollowDTOS);
                            tbFirstRecordAdapter.notifyDataSetChanged();
                            break;
                        case "肺结核患者随访记录":
                            tbFollowDTOS = viewModel.getTbFollowRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                            tbFollowAdapter.setTbFollowDTOS(tbFollowDTOS);
                            tbFollowAdapter.notifyDataSetChanged();
                            break;
                    }
                }else {
                    switch (name){
                        case "老年人中医管理记录":
                            tcmHealthDTOS = viewModel.getTCMHealthRepository().findByFieldList("isFinish",isFinish);
                            tcmHealthFollowAdapter.setTcmHealthDTOS(tcmHealthDTOS);
                            tcmHealthFollowAdapter.notifyDataSetChanged();
                            break;
                        case "高血压随访记录":
                            hypertensionFollowDTOS = viewModel.getHypertensionFollowRepository().findByFieldList("isFinish",isFinish);
                            hypertensionFollowAdapter.setHypertensionFollowDTOS(hypertensionFollowDTOS);
                            hypertensionFollowAdapter.notifyDataSetChanged();
                            break;
                        case "糖尿病随访记录":
                            diabetesFollowDTOS = viewModel.getDiabetesFollowRepository().findByFieldList("isFinish",isFinish);
                            diabetesFollowAdapter.setDiabetesFollowDTOS(diabetesFollowDTOS);
                            diabetesFollowAdapter.notifyDataSetChanged();
                            break;
                        case "肺结核患者档案":
                            tbPatientRecordDTOS = viewModel.getTbPatientRecordRepository().findByFieldList("isFinish",isFinish);
                            tbPatientRecordAdapter.setTbPatientRecordDTOS(tbPatientRecordDTOS);
                            tbPatientRecordAdapter.notifyDataSetChanged();
                            break;
                        case "肺结核患者第一次入户随访记录":
                            tbFirstFollowDTOS = viewModel.getTbFirstFollowRepository().findByFieldList("isFinish",isFinish);
                            tbFirstRecordAdapter.setTbFirstFollowDTOS(tbFirstFollowDTOS);
                            tbFirstRecordAdapter.notifyDataSetChanged();
                            break;
                        case "肺结核患者随访记录":
                            tbFollowDTOS = viewModel.getTbFollowRepository().findByFieldList("isFinish",isFinish);
                            tbFollowAdapter.setTbFollowDTOS(tbFollowDTOS);
                            tbFollowAdapter.notifyDataSetChanged();
                            break;
                    }
                }

            }
        });


       binding.material.addOnButtonCheckedListener(new MaterialButtonToggleGroup.OnButtonCheckedListener() {
           @Override
           public void onButtonChecked(MaterialButtonToggleGroup group, int checkedId, boolean isChecked) {
               if (isChecked == false)
                   return;
               switch (checkedId){
                   case R.id.unfinished:
                       isFinish = 0;
                       break;
                   case R.id.finished:
                       isFinish = 1;
                       break;
               }
               String iName = binding.editText2.getText().toString();
               if (StringUtils.isNotNull(iName)){
                   switch (name){
                       case "老年人中医管理记录":
                           tcmHealthDTOS = viewModel.getTCMHealthRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                           tcmHealthFollowAdapter.setTcmHealthDTOS(tcmHealthDTOS);
                           tcmHealthFollowAdapter.notifyDataSetChanged();
                           break;
                       case "高血压随访记录":
                           hypertensionFollowDTOS = viewModel.getHypertensionFollowRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                           hypertensionFollowAdapter.setHypertensionFollowDTOS(hypertensionFollowDTOS);
                           hypertensionFollowAdapter.notifyDataSetChanged();
                           break;
                       case "糖尿病随访记录":
                           diabetesFollowDTOS = viewModel.getDiabetesFollowRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                           diabetesFollowAdapter.setDiabetesFollowDTOS(diabetesFollowDTOS);
                           diabetesFollowAdapter.notifyDataSetChanged();
                           break;
                       case "肺结核患者档案":
                           tbPatientRecordDTOS = viewModel.getTbPatientRecordRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                           tbPatientRecordAdapter.setTbPatientRecordDTOS(tbPatientRecordDTOS);
                           tbPatientRecordAdapter.notifyDataSetChanged();
                           break;
                       case "肺结核患者第一次入户随访记录":
                           tbFirstFollowDTOS = viewModel.getTbFirstFollowRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                           tbFirstRecordAdapter.setTbFirstFollowDTOS(tbFirstFollowDTOS);
                           tbFirstRecordAdapter.notifyDataSetChanged();
                           break;
                       case "肺结核患者随访记录":
                           tbFollowDTOS = viewModel.getTbFollowRepository().findByLikeAndWhere("personName",iName,"isFinish",isFinish);
                           tbFollowAdapter.setTbFollowDTOS(tbFollowDTOS);
                           tbFollowAdapter.notifyDataSetChanged();
                           break;
                   }
               }else {
                   switch (name){
                       case "老年人中医管理记录":
                           tcmHealthDTOS = viewModel.getTCMHealthRepository().findByFieldList("isFinish",isFinish);
                           tcmHealthFollowAdapter.setTcmHealthDTOS(tcmHealthDTOS);
                           tcmHealthFollowAdapter.notifyDataSetChanged();
                           break;
                       case "高血压随访记录":
                           hypertensionFollowDTOS = viewModel.getHypertensionFollowRepository().findByFieldList("isFinish",isFinish);
                           hypertensionFollowAdapter.setHypertensionFollowDTOS(hypertensionFollowDTOS);
                           hypertensionFollowAdapter.notifyDataSetChanged();
                           break;
                       case "糖尿病随访记录":
                           diabetesFollowDTOS = viewModel.getDiabetesFollowRepository().findByFieldList("isFinish",isFinish);
                           diabetesFollowAdapter.setDiabetesFollowDTOS(diabetesFollowDTOS);
                           diabetesFollowAdapter.notifyDataSetChanged();
                           break;
                       case "肺结核患者档案":
                           tbPatientRecordDTOS = viewModel.getTbPatientRecordRepository().findByFieldList("isFinish",isFinish);
                           tbPatientRecordAdapter.setTbPatientRecordDTOS(tbPatientRecordDTOS);
                           tbPatientRecordAdapter.notifyDataSetChanged();
                           break;
                       case "肺结核患者第一次入户随访记录":
                           tbFirstFollowDTOS = viewModel.getTbFirstFollowRepository().findByFieldList("isFinish",isFinish);
                           tbFirstRecordAdapter.setTbFirstFollowDTOS(tbFirstFollowDTOS);
                           tbFirstRecordAdapter.notifyDataSetChanged();
                           break;
                       case "肺结核患者随访记录":
                           tbFollowDTOS = viewModel.getTbFollowRepository().findByFieldList("isFinish",isFinish);
                           tbFollowAdapter.setTbFollowDTOS(tbFollowDTOS);
                           tbFollowAdapter.notifyDataSetChanged();
                           break;
                   }
               }
           }
       });


    }

    private void initData() {
        Intent intent = getIntent();
        name = intent.getStringExtra("name");
        if (StringUtils.isNotNull(name)){
            switch (name){
                case "老年人中医管理记录":
                    tcmHealthDTOS = viewModel.getTCMHealthRepository().findByFieldList("isFinish",isFinish);
                    tcmHealthFollowAdapter = new TcmHealthFollowAdapter(tcmHealthDTOS,fragmentManager);
                    binding.recyclerView.setAdapter(tcmHealthFollowAdapter);
                    tcmHealthFollowAdapter.notifyDataSetChanged();
//                    if (StringUtils.isNotNull(HISConfig.PRODUCT_CODE)){
//                        TCMHealthElderlyInterface.queryTcmElderList(1000, 0,
//                                viewModel.getUserInfo().getLoginVo().getRegionCodeList().get(0), new WebServiceUtils.Response<List>() {
//                                    @Override
//                                    public void onSuccess(List result) {
//                                        if (!CollectionUtils.isEmpty(result)){
//                                            for (Object o : result) {
//                                                Map map = (Map) o;
//                                                if (map.get("ID") != null){
//                                                    String id = map.get("ID").toString();
//                                                    String personName = map.get("NAME").toString();
//                                                    TCMHealthElderlyInterface.queryTcmElderFollowDetails(id, new WebServiceUtils.Response<Map>() {
//                                                        @Override
//                                                        public void onSuccess(Map result) {
//                                                            TCMHealthDTO tcmHealthDTO = null;
//                                                            if (result.get("ot") != null){
//                                                                Map ot = (Map) result.get("ot");
//                                                                tcmHealthDTO = ReflectUtils.mapToObject(ot,TCMHealthDTO.class);
//
//                                                                if (result.get("ec") != null){
//                                                                    Map ec = (Map) result.get("ec");
//                                                                    ReflectUtils.mapToObject(ec,tcmHealthDTO);
//                                                                }
//
//                                                                tcmHealthDTO.setID(id);
//                                                                tcmHealthDTO.setPersonName(personName);
//                                                                viewModel.getTCMHealthRepository().insert(tcmHealthDTO);
//
//                                                                tcmHealthDTOS = viewModel.getTCMHealthRepository().findByFieldList("isFinish",isFinish);
//                                                                tcmHealthFollowAdapter.setTcmHealthDTOS(tcmHealthDTOS);
//                                                                tcmHealthFollowAdapter.notifyDataSetChanged();
//                                                            }
//                                                        }
//
//                                                        @Override
//                                                        public void onError(String error) {
//                                                            Utils.Toast(context,"获取老年人中医管理随访记录数据失败！\n失败原因：" + error);
//                                                        }
//                                                    });
//                                                }
//
//                                            }
//
//                                        }
//                                    }
//
//                                    @Override
//                                    public void onError(String error) {
//                                        Utils.Toast(context,"获取老年人中医管理随访记录数据失败！\n失败原因：" + error);
//                                    }
//                                });
//
//
//                    }
                    break;
                case "高血压随访记录":
                    hypertensionFollowDTOS = viewModel.getHypertensionFollowRepository().findByFieldList("isFinish",isFinish);
                    hypertensionFollowAdapter = new HypertensionFollowAdapter(hypertensionFollowDTOS,fragmentManager);
                    binding.recyclerView.setAdapter(hypertensionFollowAdapter);
                    hypertensionFollowAdapter.notifyDataSetChanged();
//                    if (StringUtils.isNotNull(HISConfig.PRODUCT_CODE)){
//                        HypertensionInterface.queryPersonalHypertensionFollowList(1000, 0, null, new WebServiceUtils.Response<List>() {
//                            @Override
//                            public void onSuccess(List result) {
//                                if (!CollectionUtils.isEmpty(result)){
//                                    for (Object o : result) {
//                                        Map data = (Map) o;
//                                        if (data.get("ID") != null){
//                                            String id = data.get("ID").toString();
//                                            String personName = data.get("PersonName").toString();
//                                            HypertensionInterface.queryPersonalHypertensionFollow(id, new WebServiceUtils.Response<Map>() {
//                                                @Override
//                                                public void onSuccess(Map result) {
//                                                    HypertensionFollowDTO hypertensionFollowDTO = null;
//
//                                                    if (result.get("CmHypertension") != null){
//                                                        Map cmHypertension = (Map) result.get("CmHypertension");
//                                                        hypertensionFollowDTO = (HypertensionFollowDTO) ReflectUtils.mapToObject(cmHypertension,HypertensionFollowDTO.class);
//                                                    }
//
//                                                    if (result.get("labora") != null){
//                                                        Map labora = (Map) result.get("labora");
//                                                        hypertensionFollowDTO.setLabora(GsonUtils.toJson(labora));
//                                                    }
//
//                                                    if (result.get("lifeStyle") != null){
//                                                        Map lifeStyle = (Map) result.get("lifeStyle");
//                                                        ReflectUtils.mapToObject(lifeStyle,hypertensionFollowDTO);
//                                                    }
//
//                                                    if (result.get("drugUseList") != null){
//                                                        Object drugUseList = result.get("drugUseList");
//                                                        hypertensionFollowDTO.setDrug(GsonUtils.toJson(drugUseList));
//                                                    }
//
//                                                    if (result.get("Body") != null){
//                                                        Map body = (Map) result.get("Body");
//                                                        ReflectUtils.mapToObject(body,hypertensionFollowDTO);
//                                                    }
//                                                    if (result.get("transout") != null){
//                                                        Map transout = (Map) result.get("transout");
//                                                        ReflectUtils.mapToObject(transout,hypertensionFollowDTO);
//                                                    }
//                                                    if (result.get("Other") != null){
//                                                        Object other =  result.get("Other");
//                                                        hypertensionFollowDTO.setOther(GsonUtils.toJson(other));
//                                                    }
//                                                    hypertensionFollowDTO.setID(id);
//                                                    hypertensionFollowDTO.setPersonName(personName);
//                                                    viewModel.getHypertensionFollowRepository().insert(hypertensionFollowDTO);
//                                                }
//
//                                                @Override
//                                                public void onError(String error) {
//                                                    Utils.Toast(context,"获取高血压随访记录数据失败！\n失败原因：" + error);
//                                                }
//                                            });
//                                        }
//                                    }
//                                    hypertensionFollowDTOS = viewModel.getHypertensionFollowRepository().findByFieldList("isFinish",isFinish);
//                                    hypertensionFollowAdapter.setHypertensionFollowDTOS(hypertensionFollowDTOS);
//                                    hypertensionFollowAdapter.notifyDataSetChanged();
//                                }
//                            }
//
//                            @Override
//                            public void onError(String error) {
//                                Utils.Toast(context,"获取高血压随访记录数据失败！\n失败原因：" + error);
//                            }
//                        });
//                    }
                    break;
                case "糖尿病随访记录":
                    diabetesFollowDTOS = viewModel.getDiabetesFollowRepository().findByFieldList("isFinish",isFinish);
                    diabetesFollowAdapter = new DiabetesFollowAdapter(diabetesFollowDTOS,fragmentManager);
                    binding.recyclerView.setAdapter(diabetesFollowAdapter);
                    diabetesFollowAdapter.notifyDataSetChanged();
//                    if (StringUtils.isNotNull(HISConfig.PRODUCT_CODE)){
//                        DiabetesInterface.queryDiabetesFollowList(null, 1000, 0, new WebServiceUtils.Response<List>() {
//                            @Override
//                            public void onSuccess(List result) {
//                                if (!CollectionUtils.isEmpty(result)){
//                                    for (Object o : result) {
//                                        Map data = (Map) o;
//                                        if (data.get("ID") != null){
//                                            String id = data.get("ID").toString();
//                                            String personName = data.get("PersonName").toString();
//                                            DiabetesInterface.queryPersonalDiabetesFollow(id, new WebServiceUtils.Response<Map>() {
//                                                @Override
//                                                public void onSuccess(Map result) {
//                                                    DiabetesFollowDTO diabetesFollowDTO = null;
//                                                    if (result.get("cmDiabetes") != null){
//                                                        Map cmDiabetes = (Map) result.get("cmDiabetes");
//                                                        diabetesFollowDTO = (DiabetesFollowDTO) ReflectUtils.mapToObject(cmDiabetes,DiabetesFollowDTO.class);
//                                                    }
//
//                                                    if (result.get("labora") != null){
//                                                        Map labora = (Map) result.get("labora");
//                                                        diabetesFollowDTO.setLabora(GsonUtils.toJson(labora));
//
//                                                    }
//                                                    if (result.get("lifeStyle") != null){
//                                                        Map lifeStyle = (Map) result.get("lifeStyle");
//                                                        ReflectUtils.mapToObject(lifeStyle,diabetesFollowDTO);
//                                                    }
//
//                                                    if (result.get("insulindrug") != null){
//                                                        Object insulindrug = result.get("insulindrug");
//                                                        diabetesFollowDTO.setInsulindrug(GsonUtils.toJson(insulindrug));
//                                                    }
//
//                                                    if (result.get("drugUseList") != null){
//                                                        Object drugUseList = result.get("drugUseList");
//                                                        diabetesFollowDTO.setDrug(GsonUtils.toJson(drugUseList));
//                                                    }
//                                                    if (result.get("Body") != null){
//                                                        Map body = (Map) result.get("Body");
//                                                        ReflectUtils.mapToObject(body,diabetesFollowDTO);
//                                                    }
//                                                    if (result.get("transout") != null){
//                                                        Map transout = (Map) result.get("transout");
//                                                        ReflectUtils.mapToObject(transout,diabetesFollowDTO);
//                                                    }
//                                                    if (result.get("Other") != null){
//                                                        Object other =  result.get("Other");
//                                                        diabetesFollowDTO.setOther(GsonUtils.toJson(other));
//                                                    }
//                                                    diabetesFollowDTO.setID(id);
//                                                    diabetesFollowDTO.setPersonName(personName);
//                                                    viewModel.getDiabetesFollowRepository().insert(diabetesFollowDTO);
//
//                                                    diabetesFollowDTOS = viewModel.getDiabetesFollowRepository().findByFieldList("isFinish",isFinish);
//                                                    diabetesFollowAdapter.setDiabetesFollowDTOS(diabetesFollowDTOS);
//                                                    diabetesFollowAdapter.notifyDataSetChanged();
//                                                }
//
//                                                @Override
//                                                public void onError(String error) {
//                                                    Utils.Toast(context,"获取糖尿病随访记录数据失败！\n失败原因：" + error);
//                                                }
//                                            });
//                                        }
//                                    }
//
//
//                                }
//                            }
//
//                            @Override
//                            public void onError(String error) {
//                                Utils.Toast(context,"获取糖尿病随访记录数据失败！\n失败原因：" + error);
//                            }
//                        });
//                    }
                    break;

                case "肺结核患者档案":
                    tbPatientRecordDTOS = viewModel.getTbPatientRecordRepository().findByFieldList("isFinish",isFinish);
                    tbPatientRecordAdapter = new TbPatientRecordAdapter(tbPatientRecordDTOS,fragmentManager);
                    binding.recyclerView.setAdapter(tbPatientRecordAdapter);
                    break;
                case "肺结核患者第一次入户随访记录":
                    tbFirstFollowDTOS = viewModel.getTbFirstFollowRepository().findByFieldList("isFinish",isFinish);
                    tbFirstRecordAdapter = new TbFirstRecordAdapter(tbFirstFollowDTOS,fragmentManager);
                    binding.recyclerView.setAdapter(tbFirstRecordAdapter);
                    tbFirstRecordAdapter.notifyDataSetChanged();
//                    if (StringUtils.isNotNull(HISConfig.PRODUCT_CODE)){
//                        List<TbPatientDTO> tbPatientDTOS = viewModel.getTbPatientRepository().findByFieldList("isFinish",isFinish);
//                        if (!CollectionUtils.isEmpty(tbPatientDTOS)){
//                            for (TbPatientDTO tbPatientDTO : tbPatientDTOS) {
//                                if (StringUtils.isNotNull(tbPatientDTO.getTBBASEID())){
//                                    TuberculosisInterface.queryTbFirstFollow(tbPatientDTO.getTBBASEID(), new WebServiceUtils.Response<List>() {
//                                        @Override
//                                        public void onSuccess(List results) {
//                                            for (Object r : results) {
//                                                Map result = (Map) r;
//                                                TbFirstFollowDTO tbFirstFollow = null;
//                                                Map examLifestyle = null;
//                                                List otherJson = null;
//                                                Map tbFirstVisit = null;
//                                                Map tbDrugUse = null;
//                                                if (result.get("examLifestyle") != null)
//                                                    examLifestyle = (Map) result.get("examLifestyle");
//                                                if (result.get("otherJson") != null)
//                                                    otherJson = (List) result.get("otherJson");
//                                                if (result.get("tbFirstVisit") != null)
//                                                    tbFirstVisit = (Map) result.get("tbFirstVisit");
//                                                if (result.get("tbDrugUse") != null)
//                                                    tbDrugUse = (Map) result.get("tbDrugUse");
//
//                                                if (tbFirstVisit == null)
//                                                    return;
//
//                                                tbFirstFollow = ReflectUtils.mapToObject(tbFirstVisit, TbFirstFollowDTO.class);
//
//                                                if (examLifestyle != null)
//                                                    ReflectUtils.mapToObject(examLifestyle,tbFirstFollow);
//                                                if (otherJson != null)
//                                                    tbFirstFollow.setOtherJson(GsonUtils.toJson(otherJson));
//                                                if (tbDrugUse != null)
//                                                    ReflectUtils.mapToObject(tbDrugUse,tbFirstFollow);
//
//                                                tbFirstFollow.setPatientId(tbPatientDTO.getPERSONID());
//                                                tbFirstFollow.setPatientName(tbPatientDTO.getNAME());
//
//                                                viewModel.getTbFirstFollowRepository().insert(tbFirstFollow);
//
//                                                tbFirstFollowDTOS = viewModel.getTbFirstFollowRepository().findByFieldList("isFinish",isFinish);
//                                                tbFirstRecordAdapter.setTbFirstFollowDTOS(tbFirstFollowDTOS);
//                                                tbFirstRecordAdapter.notifyDataSetChanged();
//                                            }
//                                        }
//
//                                        @Override
//                                        public void onError(String error) {
//                                            Utils.Toast(context,"获取肺结核患者第一次入户随访记录数据失败！\n失败原因：" + error);
//                                        }
//                                    });
//                                }
//
//                            }
//
//
//                        }
//                    }
                    break;
                case "肺结核患者随访记录":
                    tbFollowDTOS = viewModel.getTbFollowRepository().findByFieldList("isFinish",isFinish);
                    tbFollowAdapter = new TbFollowAdapter(tbFollowDTOS,fragmentManager);
                    binding.recyclerView.setAdapter(tbFollowAdapter);
                    tbFollowAdapter.notifyDataSetChanged();
//                    if (StringUtils.isNotNull(HISConfig.PRODUCT_CODE)){
//                        TuberculosisInterface.queryNewTbFollowList(1000, 0, null, new WebServiceUtils.Response<List>() {
//                            @Override
//                            public void onSuccess(List result) {
//                                if (!CollectionUtils.isEmpty(result)){
//                                    for (Object o : result) {
//                                        Map<String,Object> data = (Map) o;
//                                        TbPatientDTO tbPatientDTO = (TbPatientDTO) ReflectUtils.mapToObject(data, TbPatientDTO.class);
//                                        String id = tbPatientDTO.getID();
//                                        tbPatientDTO.setID(tbPatientDTO.getPERSONID());
//                                        viewModel.getTbPatientRepository().insert(tbPatientDTO);
//                                        TuberculosisInterface.queryNewTbFollow(null, id, new WebServiceUtils.Response<Map>() {
//                                            @Override
//                                            public void onSuccess(Map result) {
//                                                Map tbDrugUse = (Map) result.get("TbDrugUse");
//                                                Map tbFollowUp2 = (Map) result.get("TbFollowUp2");
//                                                Map examLifestyle = (Map) result.get("ExamLifestyle");
//                                                List otherText = (List) result.get("OtherText");
//                                                TbFollowDTO tbFollowDTO = (TbFollowDTO) ReflectUtils.mapToObject(tbFollowUp2,TbFollowDTO.class);
//                                                tbFollowDTO.setOtherText(GsonUtils.toJson(otherText));
//
//                                                if (StringUtils.isNotNull(tbDrugUse.get("Usage")))
//                                                    tbFollowDTO.setUsage(tbDrugUse.get("Usage").toString());
//
//                                                if (StringUtils.isNotNull(tbDrugUse.get("ChemotherapyRegimen")))
//                                                    tbFollowDTO.setChemotherapyRegimen(tbDrugUse.get("ChemotherapyRegimen").toString());
//
//                                                if (StringUtils.isNotNull(tbDrugUse.get("MissedMedNum")))
//                                                    tbFollowDTO.setMissedMedNum(String.valueOf(((Double) tbDrugUse.get("MissedMedNum")).intValue()));
//
//                                                if (StringUtils.isNotNull(tbDrugUse.get("Dosage")))
//                                                    tbFollowDTO.setDosage(String.valueOf(((Double) tbDrugUse.get("Dosage")).intValue()));
//
//                                                if (StringUtils.isNotNull(examLifestyle.get("DailyAlcoholIntake")))
//                                                    tbFollowDTO.setDailyAlcoholIntake(examLifestyle.get("DailyAlcoholIntake").toString());
//
//                                                if (StringUtils.isNotNull(examLifestyle.get("Smoking")))
//                                                    tbFollowDTO.setSmoking(examLifestyle.get("Smoking").toString());
//
//                                                tbFollowDTO.setPersonName(tbPatientDTO.getNAME());
//                                                tbFollowDTO.setPersonID(tbPatientDTO.getPERSONID());
//                                                tbFollowDTO.setTbBaseID(tbPatientDTO.getTBBASEID());
//                                                tbFollowDTO.setUpload("0");
//
//                                                viewModel.getTbFollowRepository().insert(tbFollowDTO);
//
//                                                tbFollowDTOS = viewModel.getTbFollowRepository().findByFieldList("isFinish",isFinish);
//                                                tbFollowAdapter.setTbFollowDTOS(tbFollowDTOS);
//                                                tbFollowAdapter.notifyDataSetChanged();
//                                            }
//
//                                            @Override
//                                            public void onError(String error) {
//                                                Utils.Toast(context,"获取肺结核患者随访记录数据失败！\n失败原因：" + error);
//                                            }
//                                        });
//                                    }
//                                }
//                            }
//
//                            @Override
//                            public void onError(String error) {
//                                Utils.Toast(context,"更新肺结核患者随访记录列表数据失败！\n失败原因：" + error);
//                            }
//                        });
//
//                    }
                    break;
            }
            binding.recyclerView.setLayoutManager(new LinearLayoutManager(context));
        }

    }
}
